#@admin_header()
<!-- 内容主体区域 -->
<div class="layui-body">
  <div style="padding: 15px;">
    <div class="layui-row">
      <!-- <button title="新增" onclick="add()" class="layui-btn layui-btn-normal">
        <i class="layui-icon">&#xe654;</i>新增
      </button> -->
      <a title="新增" href="#(adminRoot)/content/diary/add" class="layui-btn layui-btn-normal">
        <i class="layui-icon">&#xe654;</i>新增
      </a>
    </div>
    <div class="layui-row">
      <div class="layui-col-md12">
        <fieldset class="layui-elem-field layui-field-title">
          <legend>收录管理</legend>
        </fieldset>
        <table class="layui-table">
          <thead>
          <tr>
            <th width="30">序号</th>
            <th>内容</th>
            <th width="100">出自</th>
            <th width="100">备注</th>
            <th width="100">操作</th>
          </tr>
          </thead>
          <tbody>
          #for(x : page.getList())
          <tr id="#(x.id)">
            <td>#(for.count)</td>
            <td>#(x.content)</td>
            <td>#(x.author)</td>
            <td>#(x.remark)</td>
            <td>
              <button title="编辑"
                      onclick="javascript:window.location.href = '#(adminRoot)/content/diary/edit?id=#(x.id)'"
                      class="layui-btn layui-btn-small layui-btn-normal">
                <i class="layui-icon">&#xe642;</i></button>
              <button title="删除" onclick="del($(this).parents('tr'))"
                      class="layui-btn layui-btn-small layui-btn-danger">
                <i class="layui-icon">&#xe640;</i></button>
            </td>
          </tr>
          #end
          </tbody>
        </table>
        #@_page(page, adminRoot+ '/content/diary', '')
      </div>
    </div>
  </div>
</div>
<script>
  //JavaScript代码区域
  layui.use(['table'], function () {
  });

  /**
   * 删除分类的提示
   * @param  {Doc} dom 数据所在行的tr节点
   * @return {void}
   */
  function del(dom) {
    var index = dom.children('td').eq(0).html();
    var delLayerId = layui.layer.confirm('确定要删除第【<font size=+1>' + index + '</font>】个<br/><font color=red>删除后将不可恢复</font>',
      {
        icon: 3,
        skin: 'layui-layer-molv',
        title: '提示',
        shade: 0.3,
        shadeClose: true,
        // move: false,
        resize: false,
        offset: '100px',
        closeBtn: 0,
        btn: ['确定', '取消'],
        yes: function () {
          doDelete(dom, delLayerId);
        }
      });
  }

  /**
   * 删除分类 - 保存
   * @param  {Doc} dom 数据所在行的tr节点
   * @return {void}
   */
  function doDelete(dom, layerId) {
    var id = dom.attr('id');
    ToastLoading('正在删除...');
    $.post("#(adminRoot)/content/diary/delete/one", {id: id})
      .success(function (ret) {
        if (ret.state == 'ok') {
          ToastShow('100', ret.msg, ret.url);
          layui.layer.close(layerId);
          dom.hide(); // 隐藏删除的tr
        } else {
          ToastShow(ret.code, ret.msg, ret.url);
        }
      })
      .error(function (ret) {
        ToastErr('网络错误');
      })
  }
</script>
#@admin_footer()
